<template>
	<view class="page">
		<navigation textColor="#333333" barColor="#333333" defaultButton="back">高龄津贴</navigation>
		<view class="page_main">
			<view class="item">
				<input type="text" class="" focus="test" v-model="iDcard" value="" style="text-align: left;" placeholder="请输入用户身份证号搜索" />
				<view class="search" @click="search" style="line-height: 50rpx;">
					搜索
				</view>
			</view>
			<view class="item">
				<view class="">
					姓名
				</view>
				<input type="number"   v-model="model.username" placeholder="姓名"/>
			</view>
			<view class="item">
				<view class="picker">
					请选择津贴发放地
				</view>
				<picker mode="selector" @change="bindchange" @columnchange="columnchange" :range="addressList" range-key="name">
					<view class="picker-item">{{title}}</view>
				</picker>
			</view>
			<!-- <form-picker name="高龄津贴发放地" v-model="model.allowanceAddress" placeholder="请选择高龄津贴发放地" rangeKey="name" rangeValue="id" :range="addressList"></form-picker> -->
			<!-- <view class="item">
				<view class="">
					待遇发放标准
				</view>
				<view class="form-item__value"><view class="form-item__value-input">{{userInfo.money}}元/月</view></view>
			</view> -->
			<view class="item">
				<view class="">
					高龄津贴发放卡号
				</view>
				<input type="number"   v-model="model.allowanceCarCode" placeholder="请输入银行卡号"/>
			</view>
			
			<view class="item">
				<view class="">
					卡号归属银行
				</view>
				<input type="text" v-model="model.allowanceCarAddress" placeholder="请输入卡号归属银行" />
			</view>
		<!-- 	<form-input name="人员编号" v-model="model.allowanceCode" :value="model.allowanceCarCode" placeholder="请输入您的编号"></form-input>
			<form-picker name="高龄津贴发放地" v-model="model.allowanceAddress" placeholder="请选择高龄津贴发放地" rangeKey="name" rangeValue="id" :range="addressList"></form-picker>
			<view class="form-item">
				<view class="form-item__name disabled_name">待遇发放标准</view>
				<view class="form-item__value"><view class="form-item__value-input">{{userInfo.money}}元/月</view></view>
			</view>
			<form-input type="number" name="高龄补贴发放卡号" v-model="model.allowanceCarCode" placeholder="请输入银行卡号 "></form-input>
			<form-input name="卡号归属银行 " v-model="model.allowanceCarAddress" placeholder="请输入卡号归属银行"></form-input> -->
			<view class="form-item">
				<view class="form-item__name">认证模版照片</view>
				<view class="form-item__value">
					<view class="form-item__value-input-hint">
						请上传审核照片
					</view>
				</view>
			</view>
			<view class="photo_panel" @tap="photograph()">
				<image v-if="!model.allowanceImage" class="form-item__value-image" src="/static/images/certification01.png" mode=""></image>
				<image v-else class="form-item__value-image" mode="aspectFill" :src="model.allowanceImage"></image>
			</view>
		</view>
		<button class="page_btn" hover-class="page_btn-hover" :disabled="canSubmit" @tap="submit">确认提交</button>
	</view>
</template>

<script>
	import * as modelApi from '@/api/userApi/model.js';
	import * as commonApi from '@/api/common.js';
	import { HTTP_SERVER_URL } from '@/config';
	export default {
		data() {
			return {
				iDcard:'1',
				HTTP_SERVER_URL,
				userInfo:this.$store.getters.getUserInfo,
				model: {
					allowanceCode: '',
					allowanceRegionId:'',
					allowanceCarCode: '',
					allowanceCarAddress: '',
					allowanceImage: '',
					id:'',
					username:''
					
				},
				addressList: [],
				canSubmit:true,
				title:'请选择'
			};
		},
		created() {
			
		},
		onShow() {
			this.getAddress();
			this.iDcard=this.$store.state.idCard
		},
		methods: {
			bindchange(e){
				let a=e.target.value
				console.log(e)
				console.log(a)
				this.title=this.addressList[a].name
				console.log(this.addressList[a].id)
				this.model.allowanceRegionId=this.addressList[a].id
				// let b=e.target.value[1]
				// console.log('aaaaaaaa',b)
				
				// this.title=''+this.timeList[0][a[0]].communityName+this.timeList[1][a[1]].communityName
				// this.model.communityId=this.timeList[1][b].communityId
				// console.log(this.model.communityId)
			},
			search(){
				
				let jwt=uni.getStorageSync('open').jwt
				// console.log(jwt)
				uni.request({
					url:HTTP_SERVER_URL+'/aged/user/queryAgedBasic',
					method:'POST',
					header:{
						token:jwt
					},
					data:{
						phone:this.iDcard
					},
					success: (res) => {
						this.model.username=res.data.username
						this.model.allowanceCarAddress=res.data.allowanceCarAddress
						this.model.allowanceCarCode=res.data.allowanceCarCode
						console.log(this.model)
						console.log(res)
						if(res.data.id!=''&&res.data.id!=undefined){
							this.canSubmit=false
							this.model.id=res.data.id
							uni.showToast({
								title:'请完善以下信息',
								icon:'none'
							})
						}else{
							uni.showToast({
								title:'未找到该用户',
								icon:'none'
							})
						}
						
						// if (res.data.code==101){
						// 	uni.showToast({
						// 		title:'用户无访问权限',
						// 		icon:'none',
						// 		position:'center'
						// 	})
						// }else if(res.statusCode==200){
						// 	// this.model.allowanceCode=res.data.allowanceCode
						// 	// this.model.allowanceAddress=res.data.allowanceAddress
						// 	// this.model.allowanceCarCode=res.data.allowanceCarCode
						// 	this.model.id=res.data.id
						// 	if(this.model. haveAllowance==1){
						// 		// uni.navigateTo({
						// 		// 	url:'../allowanceAudit/allowanceAudit'
						// 		// })
						// 	}
						// 	console.log(this.model)
						// 	if(this.model.allowanceState==0){
						// 		uni.showToast({
						// 			title:"您的信息正在审核中",
						// 			icon:'none'
						// 		})
						// 	}else if(this.model.allowanceState==2){
						// 		uni.showToast({
						// 			title:'你的津贴已过期，请重新上传',
						// 			icon:'none'
						// 		})
						// 	}else if(this.model.allowanceState==undefined){
						// 		uni.showToast({
						// 			title:'您还未上传津贴',
						// 			icon:'none'
						// 		})
						// 	}else{
						// 		uni.showToast({
						// 			title:'请核对您的信息',
						// 			icon:'none'
						// 		})
						// 	}
						// }
					}
				})
			},
			getAddress(){
				commonApi
					.querySettingCommunity()
					.then(res => {
						if (res.code === 0) { 
							this.addressList = res.data;
							console.log(this.addressList)
						}
					})
					.catch(e => {
						uni.showToast({
							title: e.msg,
							icon: 'none',
							duration: 1000
						});
					});
			},
			submit(){
				// let time=new Date()
				// this.model.allowanceCreateDate=time.toLocaleString('chinese',{hour12:false})
				let jwt=uni.getStorageSync('open').jwt
				console.log(jwt)
				console.log(this.model)
				uni.request({
					url:HTTP_SERVER_URL+'/aged/user/helpAgedAllowance',
					method:'POST',
					header:{
						token:jwt
					},
					data:this.model
					,
					success: (res) => {
						console.log(res)
						if(res.statusCode==200){
							uni.showToast({
								title:'上传成功，请等待审核',
								icon:'success'
							})
						}
						uni.showToast({
							title:res.data.message,
							icon:'none',
							position:'center'
						})
					}
				})
			},
			// submit() {
			// 	modelApi
			// 		.allowance(this.model)
			// 		.then(res => {
			// 			if (res.code === 0) {
			// 				uni.showToast({
			// 					mask:true,
			// 					title: '提交成功',
			// 					duration: 1500
			// 				});
			// 				setTimeout(() => {
			// 					uni.switchTab({
			// 						url: '/pages/index/index'
			// 					});
			// 				}, 1600);
			// 			}
			// 		})
			// 		.catch(e => {
			// 			uni.showToast({
			// 				title: e.msg,
			// 				icon: 'none',
			// 				duration: 1000
			// 			});
			// 		});
			// },
			photograph(type) {
				let self = this;
				uni.chooseImage({
					count: 1,
					sourceType: ['camera'],
					sizeType: ['compressed', 'original'],
					success: res => {
						let url = '/institute/service-image/addImage';
						// #ifdef APP-PLUS || MP-WEIXIN
						url = HTTP_SERVER_URL + url;
						// #endif
						uni.uploadFile({
							url,
							filePath: res.tempFilePaths[0],
							name: 'file',
							success: uploadRes => {
								this.$set(this.model,'allowanceImage',JSON.parse(uploadRes.data).data);
								console.log(this.model.allowanceImage)
								
							},
							fail: uploadErr => {
								uni.showToast({
									title: '上传失败',
									icon: 'none',
									duration: 2000
								});
							}
						});
						// uni.uploadFile({
						// 	url:HTTP_SERVER_URL+'/admin/ocr',
						// 	filePath:res.tempFilePaths[0],
						// 	name:'file',
						// 	success:(res)=>{
						// 		console.log('上传到ocr',res)
						// 	}
						// })
					}
				});
			},
		}
	}
</script>

<style lang="stylus">
	
	.page_main {
		padding 0rpx 30rpx;
		box-sizing border-box;
	}
	.form-item__value-input-hint {
		font-size: 24rpx;
		font-family: PingFang;
		font-weight: 500;
		color: #333333;
	}

	.page_btn {
		position absolute;
		top 1350rpx;
		right 30rpx;
		left 30rpx;
	}
	.search{
		width 120rpx
		height 50rpx
		text-align center
		background-color #FB7B22
		color #FFFFFF
		font-size 36rpx
		border-radius 20rpx
	}
	.item{
		display flex
		justify-content space-between
		font-size: 28rpx;
		font-family: PingFang SC;
		font-weight: 400;
		color: #333;
		white-space: nowrap;
		line-height 110rpx
	}
	.item input{
		text-align right
		font-size 24rpx
		margin-top 30rpx
	}
	.form-item__value-image{
		width 693rpx
		height 469rpx
	}
</style>
